//
//  SWDragManager.swift
//  YiyaPuzzleDemo
//
//  Created by linhan on 16/10/10.
//  Copyright © 2016年 test. All rights reserved.
//

import Foundation
import UIKit


private let _manager:SWDragManager = SWDragManager()
class SWDragManager: NSObject
{
    class func sharedManager() -> SWDragManager
    {
        return _manager
    }
    
    //通过pageViewController获取当前在展示的两页视图上的PhotoView，用于图片交换
    weak var pageViewController:UIPageViewController?
    
    var cursor:UIView?
    weak var startView:UIView?
    
    weak var deleteView:UIView?{
        didSet{
            if let view = deleteView
            {
                let keyWindow = UIApplication.shared.keyWindow
                deleteViewRect = view.superview?.convert(view.frame, toView: keyWindow) ?? CGRectZero
                print("deleteViewRect:", view.frame, deleteViewRect, keyWindow?.frame ?? CGRectZero)
            }
        }
    }
    
    
    var deleteViewRect:CGRect = CGRectZero
    
    var deleting:Bool = false {
        didSet{
            if deleting != oldValue
            {
                deleteView?.isHidden = !deleting
            }//end deleting
        }
    }
    
    var editing:Bool = false
    
    func showCursor(_ cursor:UIView)
    {
        self.cursor = cursor
        UIApplication.shared.keyWindow?.addSubview(cursor)
    }
    
    func hideCursor()
    {
        cursor?.removeFromSuperview()
    }
    
    
    
}
